package com.derbysoft.synxisadapter.action.settings.channel;

import com.derbysoft.core.LimitedList;
import com.derbysoft.synxisadapter.action.BaseAdapterAction;
import com.derbysoft.synxisadapter.commons.model.Channel;
import com.derbysoft.synxisadapter.commons.repository.ChannelRepository;
import com.derbysoft.synxisadapter.commons.repository.impl.ChannelCondition;
import com.opensymphony.xwork2.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

@Results(value = {
    @Result(name = Action.SUCCESS, location = "/page/settings/channel/Query.ftl")
})
public class QueryAction extends BaseAdapterAction {

    @Autowired
    private ChannelRepository channelRepository;

    private LimitedList<Channel> channels = new LimitedList<Channel>();
    private ChannelCondition condition = new ChannelCondition();

    public String execute() throws Exception {
        channels = channelRepository.findByCondition(condition, createLimit());
        paging(channels);
        return SUCCESS;
    }

    public LimitedList<Channel> getChannels() {
        return channels;
    }

    public void setChannels(LimitedList<Channel> channels) {
        this.channels = channels;
    }

    public ChannelCondition getCondition() {
        return condition;
    }

    public void setCondition(ChannelCondition condition) {
        this.condition = condition;
    }
}